package com.example.sellersale.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 在表中商品Id和订单id共同构成主键
 */
@TableName("sys_order")
public class Order {
    @TableId(type = IdType.ASSIGN_ID)
    private String id;
    @TableField("goodsId")
    private String goodsId;
    @TableField("userId")
    private String userId;
    @TableField("orderNum")
    private Integer orderNum;
    @TableField("orderDate")
    private String orderDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
    private Double price;
    private String delivery;
    @TableField(exist = false)
    private User user;//一个订单只有一个购买者
    @TableField(exist = false)
    //订单和商品是一对多的关系
    private Goods goods;
    @TableField(exist = false)
    private List<Goods> goodsList = new ArrayList<>();

    public String getGoodsId() {
        return goodsId;
    }

    public void setGoodsId(String goodsId) {
        this.goodsId = goodsId;
    }

    public void addPrice(Double price){
        this.price += price;
    }
    public void addNum(Integer num){
        this.orderNum += num;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getDelivery() {
        return delivery;
    }

    public void setDelivery(String delivery) {
        this.delivery = delivery;
    }
    public String getUserId() {
        return userId;
    }
    public Goods getGoods() {
        return goods;
    }
    public void setGoods(Goods goods) {
        this.goods = goods;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public Integer getOrderNum() {
        return orderNum;
    }

    public void setOrderNum(Integer orderNum) {
        this.orderNum = orderNum;
    }

    public String getOrderDate() {
        return orderDate;
    }

    public void setOrderDate(String orderDate) {
        this.orderDate = orderDate;
    }

    public Double getPrice() {

        return price;
    }

    public void setPrice(Double price) {

        this.price = price;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public List<Goods> getGoodsList() {
        return goodsList;
    }

    public void setGoodsList(List<Goods> goodsList) {
        this.goodsList = goodsList;
    }

    @Override
    public String toString() {
        return "Order{" +
                "id='" + id + '\''  +
                ", userId='" + userId + '\'' +
                ", orderNum=" + orderNum +
                ", orderDate='" + orderDate + '\'' +
                ", price=" + price  +
                ", user=" + user +
                ", goods=" + goodsList +
                '}'+'\n';
    }
}
